import userTempId from "@/utils/userTempId"
import {getItem,setItem,removeItem} from "@/utils/localStorage"
import {reqLogin,reqUserMessage} from "@/api"
const state = {
    userTempId:userTempId(),
    token: getItem("token") || "",
    userMessage : {}
};
const mutations ={
    set_token(state,payload){
      state.token= payload.token
      setItem("token",payload.token)
    },
    set_userMessage(state,payload){
        state.userMessage = payload.userMessage
    },
    remove_token(state){
        state.token="",
       removeItem("token")
       state.userMessage={}
    }
};
const actions = {
    async get_token({commit},userInfo){
       const result = await reqLogin(userInfo)
       commit("set_token",{token:result.token})
    },

    async get_userMessage({commit}){
        const result = await reqUserMessage()
        commit("set_userMessage",{userMessage:result})
    }
};
const getters ={}

export default {
    namespaced :true,
    state,
    mutations,
    actions,
    getters
}